package com.ziyucoding.springboot.labs.lab7.shardingjdbc.readwrite.service;

import com.ziyucoding.springboot.labs.lab7.shardingjdbc.readwrite.dataobject.OrderDO;
import com.ziyucoding.springboot.labs.lab7.shardingjdbc.readwrite.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 订单服务实现类
 *
 * @author ziyucoding
 * @date 2022-10-31
 **/
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    @Transactional
    public void add(OrderDO order) {
        // 先假模假样的读取从库
        OrderDO exists = orderMapper.selectById(1);
        System.out.println(exists);
        // 插入订单
        orderMapper.insert(order);
        // 再假模假样的读取从库
        exists = orderMapper.selectById(1);
        System.out.println(exists);
    }

    @Override
    public OrderDO findById(Integer id) {
        return orderMapper.selectById(id);
    }
}
